import editorware from '../../utils/editorMiddleware'
import store from '@/store'
import { initMap } from '@/components/utils/initMap'
import { Loading } from 'element-ui'
// import { map } from 'core-js/core/array'
// import drawing from '../../tools/drawing/utils/drawing'
const trees = {
    layers: '',
    checkChange: (e, show, children) => {
        // console.log(e, show)
        if (e.type != 'folder') {
            if (e.type == 'tif') {
                let imgGraphic = [...editorware.coverageMap.values()]
                let imageLayers = map.imageryLayers._layers
                let layerList = imageLayers.filter(item => {
                    if (item._mars3d_config && item._mars3d_config.pid == e.id) {
                        return item
                    }
                })
                if (layerList && layerList.length > 0) {
                    imgGraphic.forEach((vg, i) => {
                        if (vg.pid == e.id) {
                            vg.show = show
                        }
                    })
                } else {
                    imgGraphic.forEach(vg => {
                        if (vg.pid == e.id) {
                            map.addLayer(vg)
                        }
                    })
                }
            } else {
                let layer = editorware.coverageMap.get(e.id)
                let graphicsLayers = initMap.graphicLayer.graphics
                let graphicsLayer = graphicsLayers.filter(item => {
                    if (item.id == e.id) {
                        return item
                    }
                })
                if (graphicsLayer && graphicsLayer.length == 0) {
                    initMap.graphicLayer.addGraphic(layer)
                } else {
                    if (layer) {
                        layer.show = show
                    }
                }
            }
        } else {
            if (e.editor == false && trees.layers.length > 0) {
                trees.layers.forEach(v => {
                    if (v.name == e.name) {
                        // console.log(e, show, v)
                        v.show = show
                        if (show) {
                            if (!v.isAdded) {
                                map.addLayer(v)
                            }
                        }
                    }
                })
            }
        }
        store.commit('setSingleProperty', false)
    }
}
export default trees
function getLayers() {
    new Promise((resolve, reject) => {
        if (map) {
            // console.log('辅助图层获取成功')
            trees.layers = map.getLayers({
                basemaps: true, // 是否取config.json中的basempas
                layers: true // 是否取config.json中的layers
            })
        }
    })
}
setTimeout(() => {
    getLayers()
}, 5000)
